package mybatisgen.plugin;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;

import java.util.List;

/**
 * @ClassName: com.xinmei.mybatisgen.RenameJavaMapperXmlPlugin
 * @Description: 重命名DOMapper.xml 改为 Mapper.xml; DOMapper.java 改为 DAO.java
 * @author gdw
 * @date 2017年9月7日 下午3:35:08
 */
public class RenameMapperPlugin extends PluginAdapter {
	public boolean validate(List<String> warnings) {
		return true;
    }

    @Override
    public void initialized(IntrospectedTable introspectedTable) {
        String oldXmlMapperFile = introspectedTable.getMyBatis3XmlMapperFileName();
        String newXmlMapperFile = oldXmlMapperFile.replace("DOMapper", "Mapper");
        introspectedTable.setMyBatis3XmlMapperFileName(newXmlMapperFile);
        
        String oldJavaMapperType = introspectedTable.getMyBatis3JavaMapperType();
        String newJavaMapperType = oldJavaMapperType.substring(0, oldJavaMapperType.lastIndexOf("DOMapper")) +  "DAO";
        introspectedTable.setMyBatis3JavaMapperType(newJavaMapperType);
        
        String oldExampleType = introspectedTable.getExampleType();
        String newExampleType = oldExampleType.substring(0, oldExampleType.lastIndexOf("DOExample")) + "Example";
        introspectedTable.setExampleType(newExampleType);
        
    }
}